package com.fy.pojo.enums;

import lombok.Getter;

/**
 * 账号状态枚举
 */
@Getter
public enum AccountStatusEnum {

  DISABLED(0, "禁用"),
  ENABLED(1, "正常");

  private final Integer code;
  private final String desc;

  AccountStatusEnum(Integer code, String desc) {
    this.code = code;
    this.desc = desc;
  }

  /**
   * 根据code获取枚举
   */
  public static AccountStatusEnum getByCode(Integer code) {
    if (code == null) {
      return null;
    }
    for (AccountStatusEnum status : values()) {
      if (status.getCode().equals(code)) {
        return status;
      }
    }
    return null;
  }

  /**
   * 根据描述获取枚举
   */
  public static AccountStatusEnum getByDesc(String desc) {
    if (desc == null) {
      return null;
    }
    for (AccountStatusEnum status : values()) {
      if (status.getDesc().equals(desc)) {
        return status;
      }
    }
    return null;
  }

  /**
   * 判断code是否存在
   */
  public static boolean containsCode(Integer code) {
    return getByCode(code) != null;
  }

  /**
   * 判断desc是否存在
   */
  public static boolean containsDesc(String desc) {
    return getByDesc(desc) != null;
  }
}